package com.hyt.it.ogt.ks.function;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Component
public class ExecutorFactory implements InitializingBean {

    private static ThreadPoolExecutor executor;

    private final Integer nThreads = Math.max((Runtime.getRuntime().availableProcessors() << 1) + 1, 16);

    @Override
    public void afterPropertiesSet() {
        executor = new ThreadPoolExecutor(nThreads, nThreads, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(10000));
    }

    public static ThreadPoolExecutor getThreadPoolExecutor() {
        return executor;
    }
}
